package com.kehutong.applet.admin;

import com.kehutong.applet.entity.NavigationEntity;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.orm.jdbc.JdbcSession;
import org.coraframework.orm.jdbc.Page;

/**
 * 管理后台-消息管理
 */
@MvcAction
@ReqMapping("/admin/crm/applet/navigation")
public class NavigationController {

    @Inject
    private JdbcSession sqlSession;

    // @HasPermission("crm:navigation:view")
    @ReqMapping("/list")
    public Object list(JSONObject jsonObject) {
        Page<NavigationEntity> page = sqlSession.findPage(NavigationEntity.class)
                .eq("deleted", false)
                .eq(jsonObject, "showStatus")
                .like(jsonObject,"name")
                .page(jsonObject)
                .exe();

        return page;
    }

    @Bean(newInstance=true, copy=true)
    // @HasPermission("crm:navigation:edit")
    @ReqMapping("/save")
    public Object save(NavigationEntity entity) {

        sqlSession.insert(entity);
        return Result.success();
    }

//    @HasPermission("crm:navigation:edit")
    @ReqMapping("/setStatus")
    public Object setStatus(NavigationEntity entity) {
        entity.setShowStatus(!entity.isShowStatus());
        sqlSession.updateById(entity);
        return Result.success();
    }


    @Bean(copy=true)
    // @HasPermission("crm:navigation:edit")
    @ReqMapping("/update")
    public Object update(NavigationEntity entity) {

        return sqlSession.updateById(entity);
    }

    // @Bean(copy = true)
    // @HasPermission("crm:navigation:edit")
    @ReqMapping("/delete")
    public Object delete(NavigationEntity entity) {

        return sqlSession.deleteById(entity);
    }

    @ReqMapping("/get")
    public Object get(NavigationEntity entity) {

        return Result.success(entity);
    }

}
